﻿using UnityEditor;
using UnityEngine.UIElements;

namespace E.Story
{
    /// <summary>
    /// 样式实用类
    /// </summary>
    public static class StyleUtility
    {
        /// <summary>
        /// 添加类名
        /// </summary>
        /// <param name="element">UI 元素</param>
        /// <param name="classNames">类名列表</param>
        /// <returns>UI 元素</returns>
        public static VisualElement AddClasses(this VisualElement element, params string[] classNames)
        {
            foreach (string item in classNames)
            {
                element.AddToClassList(item);
            }

            return element;
        }

        /// <summary>
        /// 添加样式表
        /// </summary>
        /// <param name="element">UI 元素</param>
        /// <param name="filePath">文件路径</param>
        /// <returns>UI 元素</returns>
        public static VisualElement AddStyleSheets(this VisualElement element, params string[] filePath)
        {
            foreach (string item in filePath)
            {
                // 载入文件
                StyleSheet styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(item);
                // 添加引用
                element.styleSheets.Add(styleSheet);
            }

            return element;
        }
    }
}